package ru.alt22.visor.php.ui.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
//import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

abstract public class AbstractActionDelegate implements IWorkbenchWindowActionDelegate {
	protected AbstractDelegatedAction action;
	private IStructuredSelection selection;

	abstract protected void init();

	public void init(IWorkbenchWindow window) {
		init();
	}
	
	public void dispose() {
		if (action != null) {
			action = null;
		}
	}
	
	public void run(IAction action) {
		if (this.action == null) {
			init();
		}
		this.action.setSelection(selection);
		this.action.run();
	}

	public void selectionChanged(IAction action, ISelection selection) {
		if (!(selection instanceof IStructuredSelection)) {
			return;
		}
		this.selection = (IStructuredSelection) selection;
	}

}
